跳到主要内容

BM24 二叉树的中序遍历

https://www.nowcoder.com/practice/0bf071c135e64ee2a027783b80bf781d

func inorderTraversal( root *TreeNode ) []int {
result := make([]int, 0)
inorder(root, &result)
return result
}

func inorder(root *TreeNode, arr *[]int) {
if root == nil {
return
}

inorder(root.Left, arr)
*arr = append(*arr, root.Val)
inorder(root.Right, arr)
}